package com.example.tuike.mapper;
import com.example.tuike.entity.UserArticles;
import org.apache.ibatis.annotations.*;

import java.util.List;
/*** @Author supersaiya
 * @Description TODO

 * @Date 2025/2/2 21:10

 * @Version 1.0*/


@Mapper
public interface UserArticlesMapper {

    @Select("SELECT * FROM UserArticles")
    List<UserArticles> findAll();

    @Select("SELECT * FROM UserArticles WHERE userArticleId = #{userArticleId}")
    UserArticles findById(@Param("userArticleId") Long userArticleId);

    @Insert("INSERT INTO UserArticles (userId, articleId, isRead, isFavorited, readAt, favoritedAt) VALUES (#{userId}, #{articleId}, #{isRead}, #{isFavorited}, #{readAt}, #{favoritedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "userArticleId")
    void insert(UserArticles userArticle);

    @Update("UPDATE UserArticles SET userId = #{userId}, articleId = #{articleId}, isRead = #{isRead}, isFavorited = #{isFavorited}, readAt = #{readAt}, favoritedAt = #{favoritedAt} WHERE userArticleId = #{userArticleId}")
    void update(UserArticles userArticle);

    @Delete("DELETE FROM UserArticles WHERE userArticleId = #{userArticleId}")
    void delete(@Param("userArticleId") Long userArticleId);
}
